Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
27 lines (21 loc) · 658 Bytes

3.6.4 - 事务模式.md

File metadata and controls

27 lines (21 loc) · 658 Bytes

事务模式

可使用multiexec实现Redis的事务模式。

使用示例

const REDIS_SERVER_HOST = '127.0.0.1';
const REDIS_SERVER_PORT = 6379;


go(function () {
    $redis = new Swoole\Coroutine\Redis();
    $redis->connect(REDIS_SERVER_HOST, REDIS_SERVER_PORT);
    $redis->multi();
    $redis->set('key3', 'rango');
    $redis->get('key1');
    $redis->get('key2');
    $redis->get('key3');

    $result = $redis->exec();
    var_dump($result);
});
  • 使用mutli指令启动事务,之后所有指令将被加入到队列中等待执行
  • 使用exec指令执行事务中的所有操作,并一次性返回所有结果